package org.example.cloud.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/4/10 14:34
 */
@RestController
@Slf4j
@RefreshScope //在控制器中添加注解@RefreshScope 使当前类下的配置支持Nacos的动态刷新功能。
public class NacosConfigClientController {
    @Value("${config.info}")
    private String configInfo;
    @Resource
    private Environment environment;

    @GetMapping("/getConfigInfo")
    public String getConfigInfo(){
        return configInfo;
    }

    @GetMapping("/getMsInnstanceName")
    public String getMSInstance(){
        String port = environment.getProperty("server.port");
        return  "微服务名字: " + environment.getProperty("spring.application.name") + "端口： " + port;
    }

}
